// 多基金指令查询页
import React from 'react';
import { DATA_ENTRY, AdvancedSearch, codeType } from '../../../comps';
import moment from 'moment';
class QueryC extends React.Component {
  state = {
    securityType: '', //类型
  };

  // 响应查询
  onQuery = (query) => {
    // 日期格式转换
    query.beginDate = query.beginDate ? query.beginDate.format('YYYY-MM-DD') : '';
    query.endDate = query.endDate ? query.endDate.format('YYYY-MM-DD') : '';
    let queryItems = {
      ...query,
      securityType: this.state.securityType,
    };
    // 抛出查询事件
    this.props.onQuery(queryItems);
  };

  // 响应重置
  onClear = () => {
    // 抛出重置事件
    this.props.onClear();
    this.setState({ securityType: '' });
    this.tradingCode.handleSearch();
  };

  // 响应证券代码点击事件
  tradingCodeChange = (e) => {
    if (e) {
      this.setState({ securityType: e.securityType });
    } else {
      this.setState({ securityType: '' });
    }
  };

  render() {
    return (
      <AdvancedSearch
        dataSource={[
          {
            dataIndex: ['beginDate', 'endDate'],
            title: '日期区间',
            type: DATA_ENTRY.RANGEDATE,
            initialValue: [moment(), moment()],
          },
          {
            dataIndex: 'tradingCode',
            title: '证券代码',
            type: DATA_ENTRY.SECURITIESCODE,
            codeType: codeType.moreFunds,
            // queryItems:{exchangeCode:'113,921'},
            onChange: (e) => this.tradingCodeChange(e),
            onRef: (ref) => (this.tradingCode = ref),
          },
          {
            dataIndex: 'productGroupId',
            multiple: true,
            type: DATA_ENTRY.PRODUCTGROUP,
          },
        ]}
        onQuery={this.onQuery}
        onClear={this.onClear}
      />
    );
  }
}

export default QueryC;
